package com.topisv.tms.web.phone;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.topisv.tms.entity.User;
import com.topisv.tms.service.AreaGroupService;
import com.topisv.tms.service.CustomersService;
import com.topisv.tms.service.UserService;

/**
 * 集发拣货装箱
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/phone")
public class WMSBasePhoneController  {

	private static final Logger log = LoggerFactory.getLogger(WMSBasePhoneController.class);
	

	@Autowired
	private CustomersService customersService;
	@Autowired
	private AreaGroupService areaGroupService;
	@Autowired
	private UserService userService;
	
	/**
	 * 
	 * 
	 * @param jobuuid
	 * @param customerCode
	 * @param response
	 */
	@RequestMapping(value = "ajaxQueryWareAndCustByJobuuid")
	public void ajaxQueryWareAndCustByJobuuid(
			@RequestParam(value = "jobuuid") String jobuuid,
			@RequestParam(value = "customerCode",required=false) String customerCode,
			HttpServletResponse response,Model model) {
		JSONObject json = null;
		PrintWriter out = null;
		try {
			json = new JSONObject();
			out = response.getWriter();
			
			User user = this.userService.findByJobuuid(jobuuid);
			json.put("customerList", customersService.findByCustomers(user.getCustomers()));
			if(StringUtils.isNotEmpty(customerCode)){
				json.put("warehouseList", areaGroupService.loadByCustomerCode(customerCode));
			}else {
				json.put("warehouseList", areaGroupService.findByAreaGroups(user.getAreagroups()));
			}
			json.put("content", "查询成功");
			json.put("status", "1");
			out.print(json.toString());
		} catch (Exception e) {
			json.put("status", "0");
			json.put("content","服务器异常");
			out.print(json.toString());
			log.error("查询仓库和商家信息异常",e);
		}
	}
	
}
